package com.congee02;

public class MaxStrength {

    public long maxStrength(int[] nums) {
        long maxNeg = 1;
        long t = 1;
        int negCnt = 0;
        int noZeroCnt = 0;
        for (int x : nums) {
            if (x == 0) {
                continue;
            }
            t *= x;
            noZeroCnt ++;
            if (x < 0) {
                negCnt ++;
                if (maxNeg == 1 || x > maxNeg) {
                    maxNeg = x;

                }
            }
        }
        long ans;
        if (noZeroCnt == 1 ||(negCnt & 1) == 0) {
            ans = t;
        } else {
            ans = t / maxNeg;
        }
        int zeroCnt = nums.length - noZeroCnt;
        return zeroCnt > 0 ? Math.max(ans, 0L) : ans;
    }

}
